-
Notifications
You must be signed in to change notification settings - Fork 1.1k
micropython/aiorepl: Add an asynchronous REPL. #524
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
5e29305 to
de26d86
Compare
|
This is brilliant, very nice, testing on ESP32-S3 currently. |
|
My initial test of this was effortlessly delightful and incredibly powerful. Thanks @jimmo |
|
Thanks @ThinkTransit & @andrewleech ! I've raised a tiny PR to the main repo (micropython/micropython#9295) which makes the REPL run by default in the context of There's a couple of little issues to iron out (Ctrl-D is a bit flakey) but as soon as the PR above is merged I think this is probably good to go for version one. |
|
@jimmo Might be a stupid question but how feasible/practical would it be to use a socket instead of sys.stdin/sys.stdout? Could this be used remotely over a network? |
If instead you mean that you want the aiorepl to be distinct to the regular REPL and have its own input/output stream, then this is also feasible to implement (we could make it so |
Thanks @jimmo I was asking about point 2 however after reading your response I now understand that this doesn't really make sense. Because aiorepl is on the standard REPL then I should just use the existing mechanisms WebREPL/BLE REPL to remotely access aiorepl! I have been using aiorepl all day now, it is a massive help for debugging/monitoring. |
|
@jimmo do you want to update this now that core supports |
Done. I've pushed an update that improves handling of Ctrl-C and Ctrl-D (based on conversation with @peterhinch).
In other words, you can Ctrl-C both The way Ctrl-C works also prevents mpremote (and similar tools) from working because they expect to see the regular REPL after two successive Ctrl-C's. So there's now also a heuristic to detect this and terminate the async REPL. |
This provides an async REPL with the following features: - Run interactive REPL in the background. - Execute statements using await. - Simple history. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
|
This version now lets me issue one-liners at the So I got ambitious and ran this script at the import uasyncio as asyncio
import gc
async def main():
while True:
gc.collect()
print(gc.mem_free())
await asyncio.sleep(2)
asyncio.run(main())This ran, with the "background" application also running, but I couldn't return to either prompt. On occasion |
Does this mean that there's two instances of |
|
Is the above issue a blocker to merging? I think we should merge this as-is, as a first step. |
|
Merged in 7602843 |
Yes, good point. I adapted my script to: import uasyncio as asyncio
import gc
async def main():
while True:
gc.collect()
print(gc.mem_free())
await asyncio.sleep(2)
asyncio.create_task(main())Now I also tried commenting out the [EDIT] --> from test import main
--> await asyncio.wait_for(main(), 20)which works beautifully. I love this enhancement - it is excellent! |
This provides an async REPL with the following features:
See documentation and example here https://github.com/jimmo/micropython-lib/tree/aiorepl/micropython/aiorepl